package com.rw.tool.util.basic.exception;

import com.rw.tool.util.string.StringFormatter;
import lombok.Getter;

/**
 * 数组长度异常
 */
@Getter
public class ArrayLengthIllegalException extends RuntimeException {
    // 错误信息模板
    private static final String errorMsg = "array length illegal! input:{}, target:{}";

    // 实际输出的长度
    private final int inputLength;
    // 合法长度
    private final int targetLength;

    public ArrayLengthIllegalException(int inputLength, int targetLength) {
        super(toMessage(inputLength, targetLength));
        this.inputLength = inputLength;
        this.targetLength = targetLength;
    }

    private static String toMessage(int inputLength, int targetLength) {
        return StringFormatter.format(errorMsg, inputLength, targetLength);
    }
}
